package com.shine.icis.action;

import java.net.URLEncoder;
import java.util.UUID;

import com.shine.cotrun.sql.QueryParameters;
import com.shine.cotrun.web.comm.ListPage;
import com.shine.cotrun.web.upload.FileDispatcher;
import com.shine.esim.struts.webutil.SessionParam;
import com.shine.icis.blo.IStockCheckService;
import com.shine.icis.config.SysConstants;
import com.shine.icis.hbean.StockCheckProcStatus;
import com.shine.icis.hbean.StockChk;
import com.shine.icis.hbean.StockChkSurv;
import com.shine.icis.util.EFRameInf;

public class StockCheckAction extends BaseAction {

	/**
	 * 股份核对
	 * @author zuohp 2012-07-21
	 * */
	private static final long serialVersionUID = 7638121893867812633L;
	
	private IStockCheckService stockCheckService;
	
	// input param
	private String  busiDate;
	private String  stockProc;
	private String  queryDate;
	private String  diffType;
	private String  compType;
	private String  exchangeType;
	private String  stockAccount;
	private String  stockCode;
	private String  srcFlag;
	
	private int pageNo;
	private int pageSize;
	private String expType;//导出方式
	
	
	//output value
	private String defaultDate;
	private StockCheckProcStatus procStatus1;//股份数据采集状态查询结果
	private StockCheckProcStatus procStatus2;//股份数据核对状态查询结果
	private StockCheckProcStatus procStatus3;//股份数据归档状态查询结果
	private StockCheckProcStatus procStatus4;//股份数据归档状态查询结果
	
	private ListPage<StockChk> stockChkPage;//核对结果查询
	private ListPage<StockChkSurv> stockChkSurvPage;//历史遗留股份不平数据查询
	private String downloadUrl;//下载地址
	private StockChk stockChk;
	
	private String note;
	//stockCheckSurv
	private long id; //主键ID
	private Integer branchNoIn ;//营业部
	private Integer oldBranchNoIn ;
	private String exchangeTypeIn ;
	private String oldExchangeTypeIn;
	private String taCodeIn;
	private String oldTaCodeIn;
	private String stockAccountIn ;
	private String oldStockAccountIn ;
	private String stockCodeIn ;
	private String oldStockCodeIn ;
	private Integer fundAccountIn ;
	private Integer oldFundAccountIn ;
	//private String clientIdIn ;
	//private String oldClientIdIn ;
	private Double dzAmountIn ;
	private Double oldDzAmountIn ;
	private Double hsAmountIn ;
	private Double oldHsAmountIn ;
	private String diffTypeIn ;
	private String oldDiffTypeIn ;
	private String noteIn ;
	private String oldNoteIn ;
	
	public void setStockCheckService(IStockCheckService stockCheckService) {
		this.stockCheckService = stockCheckService;
	}
	public String getBusiDate(){
		return busiDate;
	}
	public void setBusiDate(String busiDate) {
		this.busiDate = busiDate;
	}
	public void setStockProc(String stockProc) {
		this.stockProc = stockProc;
	}
	public void setQueryDate(String queryDate) {
		this.queryDate = queryDate;
	}
	public void setDiffType(String diffType) {
		this.diffType = diffType;
	}
	public void setCompType(String compType) {
		this.compType = compType;
	}
	public void setExchangeType(String exchangeType) {
		this.exchangeType = exchangeType;
	}
	public void setSrcFlag(String srcFlag) {
		this.srcFlag = srcFlag;
	}
	public void setStockAccount(String stockAccount) {
		this.stockAccount = stockAccount;
	}
	public void setStockCode(String stockCode) {
		this.stockCode = stockCode;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public void setExpType(String expType) {
		this.expType = expType;
	}
	
	public String getDefaultDate(){
		return defaultDate;
	}
	public StockCheckProcStatus getProcStatus1() {
		return procStatus1;
	}
	public StockCheckProcStatus getProcStatus2() {
		return procStatus2;
	}
	public StockCheckProcStatus getProcStatus3() {
		return procStatus3;
	}
	public StockCheckProcStatus getProcStatus4() {
		return procStatus4;
	}
	public ListPage<StockChk> getStockChkPage() {
		return stockChkPage;
	}
	public ListPage<StockChkSurv> getStockChkSurvPage() {
		return stockChkSurvPage;
	}
	public String getDownloadUrl() {
		return downloadUrl;
	}
	public StockChk getStockChk(){
		return stockChk;
	}
	public void setNote(String note){
		this.note = note;
	}
	public void setId(long id) {
		this.id = id;
	}
	public void setBranchNoIn(Integer branchNoIn) {
		this.branchNoIn = branchNoIn;
	}
	public void setOldBranchNoIn(Integer oldBranchNoIn) {
		this.oldBranchNoIn = oldBranchNoIn;
	}
	public void setExchangeTypeIn(String exchangeTypeIn) {
		this.exchangeTypeIn = exchangeTypeIn;
	}
	public void setOldExchangeTypeIn(String oldExchangeTypeIn) {
		this.oldExchangeTypeIn = oldExchangeTypeIn;
	}
	public void setTaCodeIn(String taCodeIn) {
		this.taCodeIn = taCodeIn;
	}
	public void setOldTaCodeIn(String oldTaCodeIn) {
		this.oldTaCodeIn = oldTaCodeIn;
	}
	public void setStockAccountIn(String stockAccountIn) {
		this.stockAccountIn = stockAccountIn;
	}
	public void setOldStockAccountIn(String oldStockAccountIn) {
		this.oldStockAccountIn = oldStockAccountIn;
	}
	public void setStockCodeIn(String stockCodeIn) {
		this.stockCodeIn = stockCodeIn;
	}
	public void setOldStockCodeIn(String oldStockCodeIn) {
		this.oldStockCodeIn = oldStockCodeIn;
	}
	public void setFundAccountIn(Integer fundAccountIn) {
		this.fundAccountIn = fundAccountIn;
	}
	public void setOldFundAccountIn(Integer oldFundAccountIn) {
		this.oldFundAccountIn = oldFundAccountIn;
	}
	public void setDzAmountIn(double dzAmountIn) {
		this.dzAmountIn = dzAmountIn;
	}
	public void setOldDzAmountIn(double oldDzAmountIn) {
		this.oldDzAmountIn = oldDzAmountIn;
	}
	public void setHsAmountIn(double hsAmountIn) {
		this.hsAmountIn = hsAmountIn;
	}
	public void setOldHsAmountIn(double oldHsAmountIn) {
		this.oldHsAmountIn = oldHsAmountIn;
	}
	public void setDiffTypeIn(String diffTypeIn) {
		this.diffTypeIn = diffTypeIn;
	}
	public void setOldDiffTypeIn(String oldDiffTypeIn) {
		this.oldDiffTypeIn = oldDiffTypeIn;
	}
	public void setNoteIn(String noteIn) {
		this.noteIn = noteIn;
	}
	public void setOldNoteIn(String oldNoteIn) {
		this.oldNoteIn = oldNoteIn;
	}
	/**
	 * 进入股份数据采集页面
	 * @return
	 */
	public String initQueryCollect() {
		try {
			int queryDate1;//当前日期
			int queryDate2;//前一个交易日
			String currentDate;
			String previousBusiDate;
			
			currentDate = stockCheckService.getCurrentDate();
			defaultDate = stockCheckService.getPreviousBusiDate(currentDate);
			previousBusiDate = stockCheckService.getPreviousBusiDate(defaultDate);
			queryDate1 = Integer.parseInt(defaultDate.trim().replaceAll("-", ""));
			queryDate2 = Integer.parseInt(previousBusiDate.trim().replaceAll("-", ""));
				
			procStatus1 = stockCheckService.getProcStatus(1, queryDate1);
			procStatus2 = stockCheckService.getProcStatus(2, queryDate1);
			procStatus3 = stockCheckService.getProcStatus(3, queryDate1);
			procStatus4 = stockCheckService.getProcStatus(4, queryDate2);
			
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}

	public String stockCollect() {
		boolean success = false;
		try {
			int queryDate;
			if(busiDate != null && !busiDate.trim().equals("")){
				queryDate = Integer.parseInt(busiDate.trim().replaceAll("-", ""));
				stockCheckService.txCallCollectProc(stockProc,queryDate,exchangeType,srcFlag);
				success = true;
			}
				return success();
			
		} catch (Exception e) {
			e.printStackTrace();
			return error(e.getMessage());
		} finally {
			//记录系统日志
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_CHECKDATA, "股份数据采集", success);
		}
	}
	/**
	 * 进入股份数据预处理页面
	 * @return
	 */
	public String initQueryPreClear() {
		try {
			int queryDate;//当前日期
			String currentDate;
			String previousBusiDate;
			
			currentDate = stockCheckService.getCurrentDate();
			defaultDate = stockCheckService.getPreviousBusiDate(currentDate);
			queryDate = Integer.parseInt(defaultDate.trim().replaceAll("-", ""));
				
			procStatus1 = stockCheckService.getProcStatus(1, queryDate);
			procStatus2 = stockCheckService.getProcStatus(2, queryDate);
			procStatus3 = stockCheckService.getProcStatus(3, queryDate);
			
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}

	public String stockPreClear() {
		boolean success = false;
		try {
			int queryDate;
			if(busiDate != null && !busiDate.trim().equals("")){
				queryDate = Integer.parseInt(busiDate.trim().replaceAll("-", ""));
				stockCheckService.txCallCollectProc(stockProc,queryDate,exchangeType,srcFlag);
				success = true;
			}
				return success();
			
		} catch (Exception e) {
			e.printStackTrace();
			return error(e.getMessage());
		} finally {
			//记录系统日志
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_CHECKDATA, "股份数据采集", success);
		}
	}
	/**
	 * 进入股份数据核对页面
	 * @return
	 */
	public String initQueryCheck() {
		try {
			int queryDate1;//当前日期
			int queryDate2;//前一个交易日
			String currentDate;
			String previousBusiDate;
			
			currentDate = stockCheckService.getCurrentDate();
			defaultDate = stockCheckService.getPreviousBusiDate(currentDate);
			previousBusiDate = stockCheckService.getPreviousBusiDate(defaultDate);
			queryDate1 = Integer.parseInt(defaultDate.trim().replaceAll("-", ""));
			queryDate2 = Integer.parseInt(previousBusiDate.trim().replaceAll("-", ""));
				
			procStatus1 = stockCheckService.getProcStatus(1, queryDate1);
			procStatus2 = stockCheckService.getProcStatus(2, queryDate1);
			procStatus3 = stockCheckService.getProcStatus(3, queryDate1);
			
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}
	public String stockCheck() {
		boolean success = false;
		try {
			int queryDate;
			if(busiDate != null && !busiDate.trim().equals("")){
				queryDate = Integer.parseInt(busiDate.trim().replaceAll("-", ""));
				stockCheckService.txCallCheckProc(stockProc,queryDate,exchangeType);
				success = true;
			}
				return success();
			
		} catch (Exception e) {
			e.printStackTrace();
			return error(e.getMessage());
		} finally {
			//记录系统日志
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_CHECKDATA, "股份数据采集", success);
		}
	}
	/**
	 * 查询
	 * @return
	 */
	public String queryStockChk() {
		if (queryDate == null || queryDate.trim().equals("")) {
			return error("参数不能为空");
		}
		QueryParameters qp = new QueryParameters();
		//设置分页信息
		qp.setPageNo(pageNo);
		qp.setPageSize(pageSize);
		
		qp.addOrder("stockAccount", true);
		qp.addOrder("stockCode", true);
		
		qp.addParameter("queryDate", Integer.parseInt(queryDate.trim().replaceAll("-", "")));
		if (diffType != null && !diffType.equals("")) {
			qp.addParameter("diffType", diffType);
			queryParameterSet("diffType",diffType,qp);
		}
		if (compType != null && !compType.equals("")) {
			qp.addParameter("compType", compType);
			queryParameterSet("compType",compType,qp);
		}
		if (exchangeType != null && !exchangeType.equals("")) {
			qp.addParameter("exchangeType", exchangeType);
			queryParameterSet("exchangeType",exchangeType,qp);
		}
		if (stockAccount != null && !stockAccount.equals("")) {
			qp.addParameter("stockAccount", stockAccount);
		}
		if (stockCode != null && !stockCode.equals("")) {
			qp.addParameter("stockCode", stockCode);
		}
		try {
			stockChkPage = stockCheckService.getStockChkPage(qp);
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}
	private void queryParameterSet(String parName,String par,QueryParameters qp){
		String[] parNameArray = par.split(",");
		qp.addParameter(parName + "Cnt", parNameArray.length);
		for (int i = 0; i < parNameArray.length; i++ ){
			qp.addParameter(parName+i, parNameArray[i]);
		}
	}
	/**
	 * 进入股份不平历史查询页面
	 * @return
	 */
	public String initQuerySurv() {
		try {
			String currentDate;
			
			currentDate = stockCheckService.getCurrentDate();
			defaultDate = stockCheckService.getPreviousBusiDate(currentDate);
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}
	/**
	 * 查询
	 * @return
	 */
	public String queryStockChkSurv() {
		if (queryDate == null || queryDate.trim().equals("")) {
			return error("参数不能为空");
		}
		QueryParameters qp = new QueryParameters();
		//设置分页信息
		qp.setPageNo(pageNo);
		qp.setPageSize(pageSize);
		qp.addOrder("exchangeType", true);
		qp.addOrder("branchNo", true);
		qp.addOrder("stockCode", true);
		qp.addOrder("stockAccount", true);
		qp.addOrder("validDate", true);
		qp.addOrder("invalidDate", true);
		
		qp.addParameter("queryDate", Integer.parseInt(queryDate.trim().replaceAll("-", "")));
		if (diffType != null && !diffType.equals("")) {
			qp.addParameter("diffType", diffType);
			queryParameterSet("diffType",diffType,qp);
		}
		if (exchangeType != null && !exchangeType.equals("")) {
			qp.addParameter("exchangeType", exchangeType);
			queryParameterSet("exchangeType",exchangeType,qp);
		}
		if (stockAccount != null && !stockAccount.equals("")) {
			qp.addParameter("stockAccount", stockAccount);
		}
		if (stockCode != null && !stockCode.equals("")) {
			qp.addParameter("stockCode", stockCode);
		}
		try {
			stockChkSurvPage = stockCheckService.getStockChkSurvPage(qp);
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}
	/**
	 * 进入股份数据备份页面
	 * @return
	 */
	public String initQueryBackup() {
		try {
			int queryDate1;//当前日期
			int queryDate2;//前一个交易日
			String currentDate;
			String previousBusiDate;
			
			currentDate = stockCheckService.getCurrentDate();
			defaultDate = stockCheckService.getPreviousBusiDate(currentDate);
			previousBusiDate = stockCheckService.getPreviousBusiDate(defaultDate);
			queryDate1 = Integer.parseInt(defaultDate.trim().replaceAll("-", ""));
			queryDate2 = Integer.parseInt(previousBusiDate.trim().replaceAll("-", ""));
				
			procStatus1 = stockCheckService.getProcStatus(1, queryDate1);
			procStatus2 = stockCheckService.getProcStatus(2, queryDate1);
			procStatus3 = stockCheckService.getProcStatus(3, queryDate1);
			procStatus4 = stockCheckService.getProcStatus(4, queryDate1);
			
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}
	/**
	 * 调用存储过程备份数据
	 * @return
	 */
	public String stockBackup() {
		boolean success = false;
		try {
			int queryDate;
			if(busiDate != null && !busiDate.trim().equals("")){
				queryDate = Integer.parseInt(busiDate.trim().replaceAll("-", ""));
				stockCheckService.txCallBackupProc(stockProc,queryDate);
				success = true;
			}
				return success();
			
		} catch (Exception e) {
			e.printStackTrace();
			return error(e.getMessage());
		} finally {
			//记录系统日志
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_CHECKDATA, "股份数据采集", success);
		}
	}
	/**
	 * 删除
	 * @return
	 */
	public String deleteStockSurv() {
		int previousDate;
		if (queryDate == null || queryDate.trim().equals("")) {
			return error("日期参数不能为空");
		}
		previousDate = Integer.parseInt(stockCheckService.getPreviousDate(queryDate).trim().replaceAll("-", ""));
		boolean success = false;
		try {
			stockCheckService.deleteStockSurv(id,previousDate);
			success = true;
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
		}
	}
	/**
	 * 新增
	 * @return
	 */
	public String addStockSurv() {
		if (queryDate == null || queryDate.trim().equals("")
				|| exchangeTypeIn == null || exchangeTypeIn.trim().equals("")
				|| stockAccountIn == null || stockAccountIn.trim().equals("")
				|| stockCodeIn == null || stockCodeIn.trim().equals("")
				|| diffTypeIn == null || diffTypeIn.trim().equals("")) {
			return error("参数不能为空");
		}
		boolean success = false;
		try {
			StockChkSurv surv = new StockChkSurv();
			surv.setBranchNo(branchNoIn == null ? 0 : branchNoIn);
			surv.setExchangeType(exchangeTypeIn);
			surv.setTaCode(taCodeIn);
			surv.setStockAccount(stockAccountIn);
			surv.setStockCode(stockCodeIn);
			surv.setFundAccount(fundAccountIn == null ? 0 : fundAccountIn);
			surv.setDzAmount(dzAmountIn);
			surv.setHsAmount(hsAmountIn);
			surv.setDiffType(diffTypeIn);
			surv.setNote(noteIn);
			surv.setValidDate(Integer.parseInt(queryDate.trim().replaceAll("-", "")));
			
			this.stockCheckService.addStockSurv(surv);
			success = true;
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
		}
	}
	/**
	 * 修改
	 * @return
	 */
	public String modifyStockSurv() {
		int validDate  = Integer.parseInt(queryDate.trim().replaceAll("-", ""));
		int previousDate = Integer.parseInt(stockCheckService.getPreviousDate(queryDate).trim().replaceAll("-", ""));
		if (queryDate == null || queryDate.trim().equals("")
				|| exchangeTypeIn == null || exchangeTypeIn.trim().equals("")
				|| stockAccountIn == null || stockAccountIn.trim().equals("")
				|| stockCodeIn == null || stockCodeIn.trim().equals("")
				|| diffTypeIn == null || diffTypeIn.trim().equals("")) {
			return error("参数不能为空");
		}
		if ((branchNoIn == null ? 0: branchNoIn) == (oldBranchNoIn == null ? 0 : oldBranchNoIn )
				&& exchangeTypeIn.trim().equals(oldExchangeTypeIn.trim()) 
				&& stockAccountIn.trim().equals(oldStockAccountIn.trim()) 
				&& stockCodeIn.trim().equals(oldStockCodeIn.trim())
				&& (fundAccountIn == null ? 0 : fundAccountIn) == (oldFundAccountIn == null ? 0 : oldFundAccountIn)
				&& (taCodeIn == null ? "" : taCodeIn).trim().equals((oldTaCodeIn == null ? "" : oldTaCodeIn).trim())
				&& (dzAmountIn == null ? 0 : dzAmountIn)== (oldDzAmountIn == null ? 0 : oldDzAmountIn)
				&& (hsAmountIn == null ? 0 : hsAmountIn)== (oldHsAmountIn == null ? 0 : oldHsAmountIn)
				&& diffTypeIn.trim().equals(oldDiffTypeIn)
				&& (noteIn == null ? "" : noteIn).trim().equals((oldNoteIn == null ? "" : oldNoteIn).trim())) {
			return error("没有改变任何项目值");
		}
		boolean success = false;
		try {
			//修改后数据
			StockChkSurv surv = new StockChkSurv();
			surv.setBranchNo(branchNoIn == null ? 0 : branchNoIn);
			surv.setExchangeType(exchangeTypeIn);
			surv.setTaCode(taCodeIn);
			surv.setStockAccount(stockAccountIn);
			surv.setStockCode(stockCodeIn);
			surv.setFundAccount(fundAccountIn == null ? 0 : fundAccountIn);
			surv.setDzAmount(dzAmountIn);
			surv.setHsAmount(hsAmountIn);
			surv.setDiffType(diffTypeIn);
			surv.setNote(noteIn);
			surv.setValidDate(validDate);
			//修改前数据
			StockChkSurv oldSurv = new StockChkSurv();
			oldSurv.setId(id);
			oldSurv.setBranchNo(oldBranchNoIn);
			oldSurv.setExchangeType(oldExchangeTypeIn);
			oldSurv.setTaCode(oldTaCodeIn);
			oldSurv.setStockAccount(oldStockAccountIn);
			oldSurv.setStockCode(oldStockCodeIn);
			oldSurv.setFundAccount(oldFundAccountIn);
			oldSurv.setDzAmount(oldDzAmountIn);
			oldSurv.setHsAmount(oldHsAmountIn);
			oldSurv.setDiffType(oldDiffTypeIn);
			oldSurv.setNote(oldNoteIn);
			//如果只修改了备注，则只更新备注
			if ((branchNoIn == null ? 0: branchNoIn) == (oldBranchNoIn == null ? 0 : oldBranchNoIn )
					&& exchangeTypeIn.trim().equals(oldExchangeTypeIn.trim()) 
					&& stockAccountIn.trim().equals(oldStockAccountIn.trim()) 
					&& stockCodeIn.trim().equals(oldStockCodeIn.trim())
					&& (fundAccountIn == null ? 0 : fundAccountIn) == (oldFundAccountIn == null ? 0 : oldFundAccountIn)
					//&& (clientIdIn == null ? "" : clientIdIn).trim().equals((oldClientIdIn == null ? "" : oldClientIdIn).trim())
					&& (taCodeIn == null ? "" : taCodeIn).trim().equals((oldTaCodeIn == null ? "" : oldTaCodeIn).trim())
					&& (dzAmountIn == null ? 0 : dzAmountIn)== (oldDzAmountIn == null ? 0 : oldDzAmountIn)
				    && (hsAmountIn == null ? 0 : hsAmountIn)== (oldHsAmountIn == null ? 0 : oldHsAmountIn)
					&& diffTypeIn.trim().equals(oldDiffTypeIn)
					&& (noteIn == null ? "" : noteIn).trim().equals((oldNoteIn == null ? "" : oldNoteIn).trim()) == false) {
				this.stockCheckService.modifySurvNote(surv,oldSurv);
			} else {
				this.stockCheckService.deleteStockSurv(id,previousDate);
				this.stockCheckService.addStockSurv(surv);
			}
			success = true;
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
		}
	}
	/**
	 * 导出Excel
	 */
	public String exportStockChk() {
		if (queryDate == null || queryDate.trim().equals("")) {
			return error("参数不能为空");
		}
		QueryParameters qp = new QueryParameters();
		qp.addOrder("exchangeType", true);
		qp.addOrder("stockCode", true);
		qp.addOrder("stockAccount", true);
		
		qp.addParameter("queryDate", Integer.parseInt(queryDate.trim().replaceAll("-", "")));
		if (diffType != null && !diffType.equals("")) {
			qp.addParameter("diffType", diffType);
			queryParameterSet("diffType",diffType,qp);
		}
		if (compType != null && !compType.equals("")) {
			qp.addParameter("compType", compType);
			queryParameterSet("compType",compType,qp);
		}
		if (exchangeType != null && !exchangeType.equals("")) {
			qp.addParameter("exchangeType", exchangeType);
			queryParameterSet("exchangeType",exchangeType,qp);
		}
		if (stockAccount != null && !stockAccount.equals("")) {
			qp.addParameter("stockAccount", stockAccount);
		}
		if (stockCode != null && !stockCode.equals("")) {
			qp.addParameter("stockCode", stockCode);
		}
		try {
			//生成一个随机文件夹保证文件不重复
			String randomDir = UUID.randomUUID().toString() + "/"; 
			String saveDir = FileDispatcher.getTempDir() + randomDir;//文件保存绝对路径
			String absDir = FileDispatcher.getTempAbsDir() + randomDir;//WEB访问的相对路径
			String temFileName = stockCheckService.csExpStockChk(qp, saveDir, expType);
			downloadUrl = absDir + URLEncoder.encode(temFileName, SysConstants.DOWNLOAD_FILENAME_ENCODING);
		} catch(Exception e) {
			e.printStackTrace();
		}
		return success();
	}
	/**
	 * 导出Excel
	 */
	public String exportStockChkSurv() {
		if (queryDate == null || queryDate.trim().equals("")) {
			return error("参数不能为空");
		}
		QueryParameters qp = new QueryParameters();
		qp.addOrder("exchangeType", true);
		qp.addOrder("stockCode", true);
		qp.addOrder("stockAccount", true);
		
		qp.addParameter("queryDate", Integer.parseInt(queryDate.trim().replaceAll("-", "")));
		if (diffType != null && !diffType.equals("")) {
			qp.addParameter("diffType", diffType);
			queryParameterSet("diffType",diffType,qp);
		}
		if (exchangeType != null && !exchangeType.equals("")) {
			qp.addParameter("exchangeType", exchangeType);
			queryParameterSet("exchangeType",exchangeType,qp);
		}
		if (stockAccount != null && !stockAccount.equals("")) {
			qp.addParameter("stockAccount", stockAccount);
		}
		if (stockCode != null && !stockCode.equals("")) {
			qp.addParameter("stockCode", stockCode);
		}
		try {
			//生成一个随机文件夹保证文件不重复
			String randomDir = UUID.randomUUID().toString() + "/"; 
			String saveDir = FileDispatcher.getTempDir() + randomDir;//文件保存绝对路径
			String absDir = FileDispatcher.getTempAbsDir() + randomDir;//WEB访问的相对路径
			String temFileName = stockCheckService.csExpStockChkSurv(qp, saveDir, expType);
			downloadUrl = absDir + URLEncoder.encode(temFileName, SysConstants.DOWNLOAD_FILENAME_ENCODING);
		} catch(Exception e) {
			e.printStackTrace();
		}
		return success();
	}
	/**
	 * 初始修改备注页面
	 */
	public String initModifyNote() {
		try {
			stockChk = stockCheckService.getStockChk(id);
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}
	/**
	 * 修改备注
	 * @return
	 */
	public String modifyNote() {
		try {
			this.stockCheckService.modifyNote(id, note);
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}
}
